#! /usr/bin/python
# encoding=utf-8
# Created by Fenglu Niu on 2025/5/27 14:03
from sqlmodel import Session, select

import common
from api.entity import CaseResult


class CaseResultService(object):
    @staticmethod
    def create_result(case_result: CaseResult, session: Session, autocommit: bool = True):
        try:
            session.add(case_result)
            if autocommit:
                session.commit()
        except Exception as e:
            common.get_logger().error('创建案件结果报错：{}', e)
            session.rollback()

    @staticmethod
    def get_result(case_id: int, session: Session):
        return session.exec(select(CaseResult).where(CaseResult.case_id == case_id)).first()
